import {createSlice} from '@reduxjs/toolkit'

export const themeSlice = createSlice({
    name: 'theme', initialState: {
        theme: window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark',
    }, reducers: {
        /**
         * toggleTheme
         * @param {*} state
         * @param {*} action
         * @description 切换主题
         */
        toggleTheme: (state, action) => {
            state.theme = action.payload
        },
    },
})

export const {toggleTheme} = themeSlice.actions

export default themeSlice.reducer